/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.comandos.admin;

import br.ufc.quixada.adrs.interfaces.Comando;
import br.ufc.quixada.adrs.model.Prazo;
import br.ufc.quixada.adrs.service.PrazoService;
import br.ufc.quixada.adrs.util.Msg;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Welligton
 */
public class CmdListarTodosAdrsForaPrazos implements Comando {

    public String executa(HttpServletRequest request, HttpServletResponse response) {

        HttpSession sessao = request.getSession(true);
        PrazoService ps = new PrazoService();
        List<Prazo> listaPrazo = new ArrayList<Prazo>();
        boolean cb2 = request.getParameter("cb") != null ? true : false;
        if (cb2) {
            String cb[] = request.getParameterValues("cb");
            for (int i = 0; i < cb.length; i++) {
                listaPrazo.add(ps.getPrazoById(Long.parseLong(cb[i])));
            }
        } else {
            sessao.setAttribute("erro", Msg.EMPTY_SELECTION_ERROR_PRAZO);
            return "/admin/admin_listar_prazos.jsp";
        }

        sessao.setAttribute("listaPrazosSelecionados", listaPrazo);

        return "/admin/admin_add_adrs_prazos.jsp";
    }
}
